using System.Collections;
using System.Collections.Generic;
using System.Runtime;

namespace Catastrophe.Common.Extensions
{
	public class ConcurrentList<T> : IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable
	{
		private List<T> _list;

		public int Count => this._list.Count;

		T IList<T>.this[int index]
		{
			get
			{
				lock (this)
				{
					return this._list[index];
				}
			}
			set
			{
				lock (this)
				{
					this._list[index] = value;
				}
			}
		}

		public bool IsReadOnly => false;

		[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
		public ConcurrentList()
		{
			this._list = new List<T>();
		}

		public ConcurrentList(IEnumerable<T> collection)
		{
			this._list = new List<T>(collection);
		}

		[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
		public ConcurrentList(int capacity)
		{
			this._list = new List<T>(capacity);
		}

		public void CopyTo(T[] array, int index)
		{
			lock (this)
			{
				this._list.CopyTo(array, index);
			}
		}

		public void Clear()
		{
			lock (this)
			{
				this._list.Clear();
			}
		}

		public bool Contains(T value)
		{
			lock (this)
			{
				return this._list.Contains(value);
			}
		}

		public int IndexOf(T value)
		{
			lock (this)
			{
				return this._list.IndexOf(value);
			}
		}

		public void Insert(int index, T value)
		{
			lock (this)
			{
				this._list.Insert(index, value);
			}
		}

		IEnumerator<T> IEnumerable<T>.GetEnumerator()
		{
			lock (this)
			{
				return this._list.GetEnumerator();
			}
		}

		public void Add(T item)
		{
			lock (this)
			{
				this._list.Add(item);
			}
		}

		public bool Remove(T item)
		{
			lock (this)
			{
				return this._list.Remove(item);
			}
		}

		public void RemoveAt(int index)
		{
			lock (this)
			{
				this._list.RemoveAt(index);
			}
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			lock (this)
			{
				return this._list.GetEnumerator();
			}
		}
	}
}
